package com.info.zhiduoduo.weixin.service;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.Condition;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.google.common.collect.Lists;
import com.info.zhiduoduo.common.baidusdk.BankcardService;
import com.info.zhiduoduo.common.baidusdk.domain.BankcardResponse;
import com.info.zhiduoduo.common.configs.CommonConfig;
import com.info.zhiduoduo.common.configs.MailConfig;
import com.info.zhiduoduo.common.configs.UploadPathConfig;
import com.info.zhiduoduo.common.configs.YunKongConfig;
import com.info.zhiduoduo.common.configs.ZddUrlConfig;
import com.info.zhiduoduo.common.constants.Constants;
import com.info.zhiduoduo.common.constants.SmartResult;
import com.info.zhiduoduo.common.constants.StatusMsg;
import com.info.zhiduoduo.common.constants.maker.MakerEntrustTaxVideoState;
import com.info.zhiduoduo.common.constants.maker.MakerType;
import com.info.zhiduoduo.common.constants.maker.StudioState;
import com.info.zhiduoduo.common.constants.project.CalcAmountType;
import com.info.zhiduoduo.common.constants.system.UserType;
import com.info.zhiduoduo.common.exception.Asserts;
import com.info.zhiduoduo.common.formbean.BaseAuthInfo;
import com.info.zhiduoduo.common.formbean.BaseSimpleFormBean;
import com.info.zhiduoduo.common.utils.DateUtil;
import com.info.zhiduoduo.common.utils.FileUtil;
import com.info.zhiduoduo.common.utils.LogUtil;
import com.info.zhiduoduo.common.utils.MD5Util;
import com.info.zhiduoduo.common.utils.NumberUtil;
import com.info.zhiduoduo.common.utils.RandomUtil;
import com.info.zhiduoduo.common.utils.StringUtil;
import com.info.zhiduoduo.core.service.CommonService;
import com.info.zhiduoduo.core.service.CoreProjectService;
import com.info.zhiduoduo.core.service.MailService;
import com.info.zhiduoduo.core.service.WxMessageService;
import com.info.zhiduoduo.core.service.common.BaseService;
import com.info.zhiduoduo.core.service.common.ContractDocService;
import com.info.zhiduoduo.core.service.common.DocService;
import com.info.zhiduoduo.core.service.impl.BankCardElementCertificationService;
import com.info.zhiduoduo.core.service.impl.CeoNoticeService;
import com.info.zhiduoduo.repository.dto.company.CompanyDetailDto;
import com.info.zhiduoduo.repository.dto.maker.MakerAnnualCheckDto;
import com.info.zhiduoduo.repository.dto.maker.MakerBankcardDto;
import com.info.zhiduoduo.repository.dto.maker.MakerDetailDto;
import com.info.zhiduoduo.repository.dto.maker.MakerFinalSettlementDto;
import com.info.zhiduoduo.repository.dto.maker.MakerIncomeDto;
import com.info.zhiduoduo.repository.dto.maker.MakerStateDto;
import com.info.zhiduoduo.repository.entity.company.Company;
import com.info.zhiduoduo.repository.entity.company.CompanyProject;
import com.info.zhiduoduo.repository.entity.maker.Maker;
import com.info.zhiduoduo.repository.entity.maker.MakerAccount;
import com.info.zhiduoduo.repository.entity.maker.MakerBankcard;
import com.info.zhiduoduo.repository.entity.maker.MakerCase;
import com.info.zhiduoduo.repository.entity.maker.MakerRescissionApply;
import com.info.zhiduoduo.repository.entity.maker.MakerStudio;
import com.info.zhiduoduo.repository.entity.maker.MakerTag;
import com.info.zhiduoduo.repository.entity.maker.StudioField;
import com.info.zhiduoduo.repository.entity.maker.Tag;
import com.info.zhiduoduo.repository.entity.taxer.TaxerInviteCode;
import com.info.zhiduoduo.repository.entity.taxer.TaxerPayment;
import com.info.zhiduoduo.repository.mapper.company.CompanyMapper;
import com.info.zhiduoduo.repository.mapper.crowdsource.CrowdsourceAccountMapper;
import com.info.zhiduoduo.repository.mapper.maker.MakerAccountMapper;
import com.info.zhiduoduo.repository.mapper.maker.MakerAccountflowMapper;
import com.info.zhiduoduo.repository.mapper.maker.MakerAnnualCheckMapper;
import com.info.zhiduoduo.repository.mapper.maker.MakerBankcardMapper;
import com.info.zhiduoduo.repository.mapper.maker.MakerCaseMapper;
import com.info.zhiduoduo.repository.mapper.maker.MakerFinalSettlementMapper;
import com.info.zhiduoduo.repository.mapper.maker.MakerFinishTaxMapper;
import com.info.zhiduoduo.repository.mapper.maker.MakerMapper;
import com.info.zhiduoduo.repository.mapper.maker.MakerTagMapper;
import com.info.zhiduoduo.repository.mapper.partner.PartnerMapper;
import com.info.zhiduoduo.repository.mapper.taxer.TaxerInviteCodeMapper;
import com.info.zhiduoduo.weixin.formbean.crowdsource.CompanyExamineFormBean;
import com.info.zhiduoduo.weixin.formbean.crowdsource.UpdateEmergencyContactFormBean;
import com.info.zhiduoduo.weixin.formbean.maker.*;
import com.info.zhiduoduo.weixin.formbean.project.ProjectIdFormBean;
import com.info.zhiduoduo.weixin.formbean.system.RegFormBean;
import com.info.zhiduoduo.wxsdk.WxApiService;
import com.info.zhiduoduo.wxsdk.domain.app.WxAuthorizeAccessToken;
import com.info.zhiduoduo.wxsdk.domain.app.WxAuthorizeUserInfo;

import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.client.RestTemplate;

import java.io.File;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import javax.annotation.Resource;
import javax.validation.Valid;

@Transactional
@Service
public class MakerService extends BaseService {

	@Autowired
	CommonService commonService;
	@Autowired
	DocService docService;
	@Autowired
	ContractDocService contractDocService;
	@Autowired
	MailService mailService;
	@Autowired
	WxApiService wxApiService;
	@Autowired
	WxMessageService wxMessageService;
	@Autowired
	CeoNoticeService ceoNoticeService;
	@Autowired
	BankcardService bankcardService;

	@Resource
	MakerMapper makerMapper;
	@Resource
	CompanyMapper companyMapper;
	@Resource
	MakerAccountMapper makerAccountMapper;
	@Resource
	MakerBankcardMapper makerBankcardMapper;
	@Resource
	MakerTagMapper makerTagMapper;
	@Resource
	MakerAccountflowMapper makerAccountflowMapper;
	@Resource
	CoreProjectService coreProjectService;
	@Resource
	MakerFinishTaxMapper makerFinishTaxMapper;
	@Resource
	TaxerInviteCodeMapper taxerInviteCodeMapper;
	@Resource
	MakerAnnualCheckMapper makerAnnualCheckMapper;
	@Resource
	MakerFinalSettlementMapper makerFinalSettlementMapper;
	@Resource
	PartnerMapper partnerMapper;
	@Resource
	CrowdsourceAccountMapper crowdsourceAccountMapper;
	@Resource
	MakerCaseMapper makerCaseMapper;

	@Autowired
	CommonConfig commonConfig;
	@Autowired
	MailConfig mailConfig;
	@Autowired
	ZddUrlConfig zddUrlConfig;
	@Autowired
	YunKongConfig yunKongConfig;
	@Resource
	UploadPathConfig uploadPathConfig;
	@Autowired
	BankCardElementCertificationService bankCardElementCertificationService;

	@Value("${uploadpath}")
	private String uploadPath;


	public SmartResult regUser(BaseSimpleFormBean<RegFormBean> baseSimpleFormBean) {

		RegFormBean regFormBean = baseSimpleFormBean.getReqdata();

		if (null == regFormBean || StringUtil.isEmpty(regFormBean.getPhone()) || StringUtil.isEmpty(regFormBean.getVerifycode()) ||
				baseSimpleFormBean.getUserid() == 0) {
			return SmartResult.fail(StatusMsg.StatusMsg_101);
		}

		int userid = baseSimpleFormBean.getUserid();

		String phone = regFormBean.getPhone();

		Maker maker = new Maker().selectById(userid);
		if (null == maker) {
			return SmartResult.fail(StatusMsg.StatusMsg_201);
		} else if (maker.getState() >= Constants.user_state_2) {
			return SmartResult.fail(StatusMsg.StatusMsg_213);
		}

		commonService.checkPhoneVerifyCode(phone, regFormBean.getVerifycode());

		//查看企业是否已经注册
		Company company = companyMapper.checkCompanyExistByPhone(phone);
		if (null != company) {
			return SmartResult.fail(StatusMsg.StatusMsg_116);
		}

		//查看个人是否已经注册
		Maker existMaker = makerMapper.checkUserExistByPhone(phone);
		if (null != existMaker) {
			int makerType = NumberUtil.safeInt(existMaker.getMakerType());
			if (makerType == MakerType.INTELL) {
				return SmartResult.fail(StatusMsg.StatusMsg_118);
			} else if (makerType == MakerType.TAXER) {
				return SmartResult.fail(StatusMsg.StatusMsg_706);
			} else if (makerType == MakerType.CROWDSOURCE) {
				// 众包创客切换为 创客
				MakerStudio makerStudio = new MakerStudio().selectById(existMaker.getUserid());
				if (makerStudio != null && NumberUtil.equals(makerStudio.getCrowdsourceConvertZddMaker(), Constants.TRUE)) {
					convertCrowdsrouce2ZddMaker(existMaker, maker);
					MakerAccount makerAccount = new MakerAccount().selectOne(Condition.create().eq("userid", existMaker.getUserid()));
					MakerStateDto makerStateDto = new MakerStateDto()
							.setUserid(makerAccount.getUserid())
							.setAuthState(makerAccount.getRealnameAuth());
					return SmartResult.success(makerStateDto);
				} else {
					return SmartResult.fail(StatusMsg.StatusMsg_636);
				}
			}
		}

		//验证 的邀请码是否有效
		if (baseSimpleFormBean.getIdtype() == UserType.TAXER) {
			String inviteCode = regFormBean.getInviteCode();
			if (StringUtil.isNotEmpty(inviteCode)) {
				TaxerInviteCode taxerInviteCode = taxerInviteCodeMapper.selectByCode(inviteCode);
				if (taxerInviteCode == null) {
					return SmartResult.fail(StatusMsg.StatusMsg_505);
				} else {
					maker.setTaxerInviteCode(inviteCode);
				}
			}
		}
		//更新用户手机号
		maker.setPhone(phone);
		maker.setState(Constants.user_state_2);
		if (maker.updateById()) {
			//注册成功，创建创客账户
			new MakerAccount().setUserid(maker.getUserid()).setRealnameAuth(Constants.realname_auth_1).insert();
		}
		return SmartResult.success();
	}

	/**
	 * 处理智众包创客转换成 创客.需要修改如下数据:
	 * <p> 将新注册的 创客的openid赋值给智众包创客对象.
	 * <p> 修改老智众包创客对象的创客类型为 创客.
	 * <p> 保存老智众包创客的openid
	 * <p> 删除新注册的这个 创客.
	 *
	 * @param crowdsourceMaker
	 * @param newMaker
	 * @return
	 */
	private void convertCrowdsrouce2ZddMaker(Maker crowdsourceMaker, Maker newMaker) {
		String crowdsourceOpenid = crowdsourceMaker.getOpenid();
		crowdsourceMaker.setOpenid(newMaker.getOpenid()).setCrowdsourceOpenid(crowdsourceOpenid).setMakerType(MakerType.INTELL);
		crowdsourceMaker.updateById();
		newMaker.deleteById();
	}

	public SmartResult getUserInfo(BaseAuthInfo baseAuthInfo) {
		SmartResult smartResult = new SmartResult();

		MakerDetailDto userInfo = getUserInfo(baseAuthInfo.getUserid());

		if (null == userInfo) {
			smartResult.setStateMsg(StatusMsg.StatusMsg_201);
			return smartResult;
		}

		smartResult.setObject(userInfo);
		return smartResult;

	}

	public MakerDetailDto getUserInfo(int userid) {
		MakerDetailDto user = makerMapper.getUserDetail(userid);
		if (user == null) {
			return null;
		}
		if (user.getMakerType() == MakerType.TAXER && StringUtil.isNotEmpty(user.getTaxerInviteCode())) {
			TaxerInviteCode taxerInviteCode = taxerInviteCodeMapper.selectByCode(user.getTaxerInviteCode());
			if (taxerInviteCode != null) {
				user.setTaxerInviteName(taxerInviteCode.getInviteName())
						.setTaxerInviteAmount(taxerInviteCode.getAmount())
						.setTaxerInviteRemark(taxerInviteCode.getRemark());
			}
		}
		user.setTagList(makerTagMapper.getUserTagList(userid));
		return user;
	}

	public SmartResult updateBizScope(BaseSimpleFormBean<BizScopeFormBean> baseSimpleFormBean) {
		SmartResult smartResult = new SmartResult();

		BizScopeFormBean bizScopeFormBean = baseSimpleFormBean.getReqdata();

		if (null == bizScopeFormBean || StringUtil.isEmpty(bizScopeFormBean.getBizscope())) {
			smartResult.setStateMsg(StatusMsg.StatusMsg_101);
			return smartResult;
		}

		int userid = baseSimpleFormBean.getUserid();
		int tradecategoryid = bizScopeFormBean.getTradecategoryid();
		String bizscope = bizScopeFormBean.getBizscope();

		new MakerStudio().setUserid(userid).setTradecategoryid(tradecategoryid).setBizscope(bizscope).updateById();
		return smartResult;
	}

	public SmartResult updateUserInfo(BaseSimpleFormBean<UpdateMakerInfoFormBean> baseSimpleFormBean) {
		SmartResult smartResult = new SmartResult();

		UpdateMakerInfoFormBean updateMakerInfoFormBean = baseSimpleFormBean.getReqdata();

		if (null == updateMakerInfoFormBean) {
			smartResult.setStateMsg(StatusMsg.StatusMsg_101);
			return smartResult;
		}

		int userid = baseSimpleFormBean.getUserid();
		Maker maker = new Maker().selectById(userid);
		MakerStudio makerStudio = new MakerStudio().selectById(userid);
		if (null == maker) {
			smartResult.setStateMsg(StatusMsg.StatusMsg_201);
			return smartResult;
		}
		if (null == makerStudio || makerStudio.getState() != StudioState.CONFIRMED) {
			smartResult.setStateMsg(StatusMsg.StatusMsg_204);
			return smartResult;
		}

		//更新基础资料
		BeanUtils.copyProperties(updateMakerInfoFormBean, maker);
		maker.updateById();

		//更新工作室资料
		BeanUtils.copyProperties(updateMakerInfoFormBean, makerStudio);
		makerStudio.updateById();

		//更新创客标签
		HashSet<Integer> newTagids = new HashSet<>();
		List<MakerTag> oldTagList = new MakerTag().selectList(Condition.create().eq("userid", userid));
		String usertag = updateMakerInfoFormBean.getUsertag();
		if (StringUtil.isNotEmpty(usertag)) {
			newTagids.addAll(Arrays.stream(usertag.split(",")).map(StringUtil::toInt).collect(Collectors.toList()));
		}

		//删除老标签
		oldTagList.stream()
				.mapToInt(MakerTag::getTagid)
				//当新的标签ids中没有这个老标签的id,说明需要删除这个老的
				.filter(oldTagid -> !newTagids.contains(oldTagid))
				.forEach(oldTagid -> new MakerTag().delete(Condition.create().eq("userid", userid).eq("tagid", oldTagid)));

		//添加新标签
		newTagids.stream().distinct().filter(NumberUtil::isAllPositive)
				//当所有老标签中都没有这个id,则是新标签,需要添加这个标签
				.filter(tagid -> oldTagList.stream().noneMatch(ut -> tagid.equals(ut.getTagid()))).forEach(tagid -> {
			new MakerTag().setUserid(userid).setTagid(tagid).insert();
			//更新标签的排序值
			new Tag().setTagid(tagid).updateById();
		});
		return smartResult;
	}

	public SmartResult realNameAuth(BaseSimpleFormBean<RealNameAuthFormBean> baseSimpleFormBean) {
		SmartResult smartResult = new SmartResult();

		RealNameAuthFormBean reqdata = baseSimpleFormBean.getReqdata();

		if (null == reqdata) {
			smartResult.setStateMsg(StatusMsg.StatusMsg_101);
			return smartResult;
		}

		int userid = baseSimpleFormBean.getUserid();

		Maker maker = new Maker().selectById(userid);
		if (null == maker) {
			smartResult.setStateMsg(StatusMsg.StatusMsg_201);
			return smartResult;
		}

		maker.setCompremark(reqdata.getCompremark())
				.setHasCompany(reqdata.getHasCompany())
				.setHasContract(reqdata.getHasContract())
				.setWorkComapny(reqdata.getWorkCompany())
				.updateById();

		MakerAccount makerAccount = makerAccountMapper.getUserAccountByUserId(userid);

		if (null == makerAccount) {

			// 判断身份证有没有注册过
			int makerCount = new MakerAccount().selectCount(
					Condition.create().eq("idno", reqdata.getIdno()).ge("realname_auth", Constants.realname_auth_2));
			Asserts.equalZero(makerCount, StatusMsg.StatusMsg_225);

			makerAccount = new MakerAccount().setUserid(userid).setRealnameAuth(Constants.realname_auth_2);
			BeanUtils.copyProperties(reqdata, makerAccount);
			makerAccount.setAuthSubmitTime(new Date());
			makerAccount.setNameOfEmergencyContact(reqdata.getNameOfEmergencyContact());
			makerAccount.setPhoneOfEmergencyContact(reqdata.getPhoneOfEmergencyContact());
			makerAccount.insert();
			ceoNoticeService.recordMakerVerify(userid, 0);
		} else {
			//重新提交资料
			//判断身份证有没有注册过
			if (!StringUtil.equals(makerAccount.getIdno(), reqdata.getIdno())) {

				int makerCount = new MakerAccount().selectCount(Condition.create()
						.ne("acctid", makerAccount.getAcctid())
						.eq("idno", reqdata.getIdno())
						.ge("realname_auth", Constants.realname_auth_2));
				Asserts.equalZero(makerCount, StatusMsg.StatusMsg_225);
			}

			BeanUtils.copyProperties(reqdata, makerAccount);
			makerAccount.setRealnameAuth(Constants.realname_auth_2);
			makerAccount.updateById();
		}

		// 用户申请注册，新建一个注册审核支付记录
		if (maker.getMakerType() == MakerType.TAXER && NumberUtil.safeInt(maker.getPayid()) == 0) {
			String payno = RandomUtil.createRandomNo("TAX_", "");
			TaxerInviteCode taxerInviteCode = new TaxerInviteCode().selectOne(
					Condition.create().eq("invite_code", maker.getTaxerInviteCode()));

			BigDecimal amount;
			if (taxerInviteCode == null) {
				amount = BigDecimal.valueOf(commonConfig.getTaxerRegisterFee());
			} else {
				amount = taxerInviteCode.getAmount();
			}

			TaxerPayment payment = new TaxerPayment().setType(Constants.TAXER_PAY_TYPE_VERIFY)
					.setUserid(userid)
					.setPayno(payno)
					.setAmount(amount)
					.setState(1);
			if (payment.insert()) {
				maker.setPayid(payment.getPayid()).updateById();
			}
		}

		wxMessageService.notifyCustomerAgents(makerAccount.getAcctid());

		return smartResult;
	}

	public SmartResult updateRealNameInfo(BaseSimpleFormBean<RealNameAuthFormBean> formBean) {
		SmartResult smartResult = new SmartResult();

		RealNameAuthFormBean reqdata = formBean.getReqdata();

		if (null == reqdata) {
			smartResult.setStateMsg(StatusMsg.StatusMsg_101);
			return smartResult;
		}

		int userid = formBean.getUserid();

		Maker maker = new Maker().selectById(userid);
		if (null == maker) {
			smartResult.setStateMsg(StatusMsg.StatusMsg_201);
			return smartResult;
		}

		maker.setCompremark(reqdata.getCompremark())
				.setHasCompany(reqdata.getHasCompany())
				.setHasContract(reqdata.getHasContract())
				.setWorkComapny(reqdata.getWorkCompany())
				.updateById();

		MakerAccount makerAccount = makerAccountMapper.getUserAccountByUserId(userid);
		//重新提交资料
		BeanUtils.copyProperties(reqdata, makerAccount);
		makerAccount.setRealnameAuth(Constants.realname_auth_2);
		makerAccount.updateById();

		return smartResult;
	}

	public SmartResult updatePayPwd(BaseSimpleFormBean<PayPwdFormBean> baseSimpleFormBean) {
		SmartResult smartResult = new SmartResult();

		PayPwdFormBean payPwdFormBean = baseSimpleFormBean.getReqdata();

		if (null == payPwdFormBean || StringUtil.isEmpty(payPwdFormBean.getPayPassword())) {
			smartResult.setStateMsg(StatusMsg.StatusMsg_101);
			return smartResult;
		}

		String payPwd = payPwdFormBean.getPayPassword();
		int userid = baseSimpleFormBean.getUserid();

		MakerAccount makerAccount = makerAccountMapper.getUserAccountByUserId(userid);

		if (null == makerAccount) {
			smartResult.setStateMsg(StatusMsg.StatusMsg_201);
			return smartResult;
		}

		String salt = RandomUtil.generateString(8);
		makerAccount.setSalt(salt);
		makerAccount.setPayPassword(MD5Util.md5(payPwd + salt));
		makerAccount.updateById();

		return smartResult;
	}

	public SmartResult getPayPwdForCheck(BaseSimpleFormBean<PayPwdFormBean> baseSimpleFormBean) {
		SmartResult smartResult = new SmartResult();

		PayPwdFormBean payPwdFormBean = baseSimpleFormBean.getReqdata();

		if (null == payPwdFormBean || StringUtil.isEmpty(payPwdFormBean.getPayPassword())) {
			smartResult.setStateMsg(StatusMsg.StatusMsg_101);
			return smartResult;
		}

		String payPwd = payPwdFormBean.getPayPassword();
		int userid = baseSimpleFormBean.getUserid();

		MakerAccount makerAccount = makerAccountMapper.getUserAccountByUserId(userid);
		if (null == makerAccount) {
			smartResult.setStateMsg(StatusMsg.StatusMsg_201);
			return smartResult;
		}

		String salt = makerAccount.getSalt();
		String md5PayPwd = MD5Util.md5(payPwd + salt);

		if (!md5PayPwd.equals(makerAccount.getPayPassword())) {
			smartResult.setStateMsg(StatusMsg.StatusMsg_113);
			return smartResult;
		}

		return smartResult;

	}

	public SmartResult updatePayPwdForForget(BaseSimpleFormBean<ForgetPayPwdFormBean> baseSimpleFormBean) {
		SmartResult smartResult = new SmartResult();

		ForgetPayPwdFormBean forgetPayPwdFormBean = baseSimpleFormBean.getReqdata();

		if (null == forgetPayPwdFormBean) {
			smartResult.setStateMsg(StatusMsg.StatusMsg_101);
			return smartResult;
		}

		int userid = baseSimpleFormBean.getUserid();
		String phone = forgetPayPwdFormBean.getPhone();
		String verifyCode = forgetPayPwdFormBean.getVerifycode();

		Maker maker = new Maker().selectById(userid);
		if (!maker.getPhone().equals(phone)) {
			smartResult.setStateMsg(StatusMsg.StatusMsg_114);
			return smartResult;
		}

		commonService.checkPhoneVerifyCode(phone, verifyCode);

		MakerAccount makerAccount = makerAccountMapper.getUserAccountByUserId(userid);

		if (null == makerAccount) {
			return smartResult((StatusMsg.StatusMsg_201));
		}

		String salt = RandomUtil.generateString(8);
		makerAccount.setSalt(salt);
		makerAccount.setPayPassword(MD5Util.md5(forgetPayPwdFormBean.getPayPassword() + salt));
		makerAccount.updateById();

		return smartResult();
	}

	/**
	 * @param formBean
	 * @return
	 */
	public SmartResult bankcardAuth(BaseSimpleFormBean<BankcardAuthFormBean> formBean) {
		BankcardAuthFormBean reqdata = formBean.getReqdata();
		int userid = formBean.getUserid();
		if (userid <= 0 || reqdata == null) return errorParamSmartResult();
		if (StringUtil.isAnyEmpty(reqdata.getAcctno(), reqdata.getBankname())) {
			return errorParamSmartResult();
		}
		JSONObject  jsonObject = bankCardElementCertificationService.homeQuery(reqdata.getAcctno());
		if (!BankCardElementCertificationService.TYPE.equals(jsonObject.getString("type"))){
			return smartResult(StatusMsg.BANKCARD_TYPE);
		}
		//现将其他已经绑了的银行卡置为失效
		new MakerBankcard().setState(2).update(Condition.create().eq("userid", userid).eq("accttype", Constants.BANK_ACCT_TYPE_PERSONAL));
		//检查是否存在这张卡
		MakerBankcard bankcard = new MakerBankcard().selectOne(Condition.create().eq("userid", userid).eq("acctno", reqdata.getAcctno()));
		if (bankcard != null) {
			bankcard.setState(1);
		} else {
			bankcard = new MakerBankcard().setUserid(userid).setAccttype(Constants.BANK_ACCT_TYPE_PERSONAL).setState(1);
		}
		BeanUtils.copyProperties(reqdata, bankcard);
		bankcard.setCardName(jsonObject.getString("cardName"))
				.setProvince(jsonObject.getString("province"))
				.setCity(jsonObject.getString("city"));

		if (bankcard.insertOrUpdate()) {
			return smartResult();
		}

		return optFailSmartResult();
	}

	/**
	 * 获取绑定的有效银行卡
	 */
	public SmartResult getValidBankcard(BaseSimpleFormBean formBean) {
		int userid = formBean.getUserid();
		int idtype = formBean.getIdtype();
		if (NumberUtil.isAnyZero(userid, idtype)) {
			return errorParamSmartResult();
		}

		MakerBankcardDto bankcard = makerBankcardMapper.getUserValidBankcard(userid);
		return smartResult(bankcard);
	}

	/**
	 * 获取所有的标签
	 */
	public SmartResult getAllTag(BaseSimpleFormBean formBean) {
		int userid = formBean.getUserid();
		List<Tag> tags = new Tag().selectList(Condition.create().orderBy("sort", false));

		return smartResult(tags);
	}

	/**
	 * 用户添加标签
	 */
	public SmartResult addTag(BaseSimpleFormBean<String> formBean) {
		int userid = formBean.getUserid();
		String tagname = formBean.getReqdata();
		if (StringUtil.isEmpty(tagname)) return errorParamSmartResult();
		if (tagname.length() > 10) return smartResult(StatusMsg.StatusMsg_117);

		Tag tag = new Tag().selectOne(Condition.create().eq("tagname", tagname));
		if (tag == null) {
			tag = new Tag().setTagname(tagname).setCreatetime(new Date());
			if (!tag.insert()) {
				return optFailSmartResult();
			}
		}

		//添加到用户的标签组
		int count = new MakerTag().selectCount(Condition.create().eq("tagid", tag.getTagid()).eq("userid", userid));
		if (count == 0) {
			new MakerTag().setTagid(tag.getTagid()).setUserid(userid).insert();
			return smartResult(tag);
		}

		return optFailSmartResult();
	}

	public SmartResult getDefaultTagList(BaseSimpleFormBean formBean) {
		List<Tag> list = new Tag().selectList(Condition.create().eq("type", Constants.TAG_DEFAULT));
		return smartResult(list);
	}

	/**
	 * 获取所有工作室领域分类
	 */
	public SmartResult getAllField(BaseSimpleFormBean formBean) {
		List<StudioField> list = new StudioField().selectAll();

		return smartResult(list);
	}

	/**
	 * 创客添加案例
	 */
	public SmartResult addEditCase(BaseSimpleFormBean<AddCaseFormBean> formBean) {

		int userid = formBean.getUserid();
		AddCaseFormBean reqdata = formBean.getReqdata();
		if (userid <= 0 || reqdata == null) return errorParamSmartResult();

		int caseid = reqdata.getCaseid();
		String casename = reqdata.getCasename();
		String casedesc = reqdata.getCasedesc();
		String caseimgs = reqdata.getCaseimgs();
		String startDate = reqdata.getStartDate();
		String endDate = reqdata.getEndDate();

		if (StringUtil.isAnyEmpty(casename, casedesc)) {
			return errorParamSmartResult();
		}

		MakerCase makerCase;
		if (caseid == 0) {
			//新增
			makerCase = new MakerCase().setUserid(userid);
		} else {
			//编辑
			makerCase = new MakerCase().selectById(caseid);
			if (makerCase == null || makerCase.getUserid() == null || userid != makerCase.getUserid()) {
				return errorParamSmartResult();
			}
		}

		makerCase.setCasename(casename).setCasedesc(casedesc).setCaseimgs(caseimgs).setStartDate(startDate).setEndDate(endDate);

		if (makerCase.insertOrUpdate()) {
			return smartResult();
		}
		return optFailSmartResult();
	}

	/**
	 * 获取案例列表
	 */
	public SmartResult getCaseList(BaseSimpleFormBean formBean) {

		int userid = formBean.getUserid();
		Page<Object> page = PageHelper.startPage(formBean.getPage(), formBean.getRows());
		List<MakerCase> list = makerCaseMapper.listByUserid(userid);

		return smartResult(list, page.getTotal(), page.getPages(), page.getPageNum());
	}

	/**
	 * 删除案例
	 */
	public SmartResult delCase(BaseSimpleFormBean<Integer> formBean) {
		int userid = formBean.getUserid();
		Integer caseid = formBean.getReqdata();

		boolean delete = new MakerCase().delete(Condition.create().eq("userid", userid).eq("caseid", caseid));

		if (delete) return smartResult();

		return optFailSmartResult();
	}

	public SmartResult getUserByOpenid(BaseSimpleFormBean<String> formBean) {
		String openid = formBean.getReqdata();
		Maker makerByOpenid = makerMapper.getUserByOpenid(openid);

		return smartResult(makerByOpenid);
	}

	public SmartResult bindUser(BaseSimpleFormBean<BindMakerFormBean> formBean) {

		BindMakerFormBean reqdata = formBean.getReqdata();
		String code = reqdata.getCode();
		String phone = reqdata.getPhone();
		String verifycode = reqdata.getVerifycode();

		WxAuthorizeAccessToken authorizeAccessToken = wxApiService.getAuthorizeAccessToken(code);
		if (authorizeAccessToken == null) {
			return smartResult(StatusMsg.StatusMsg_101);
		}

		String openid = authorizeAccessToken.getOpenid();
		String accessToken = authorizeAccessToken.getAccess_token();

		Maker makerByOpenid = makerMapper.getUserByOpenid(openid);
		if (makerByOpenid != null) {
			if (NumberUtil.safeInt(makerByOpenid.getState()) > 1) {
				//openid已经注册并认证了手机号，不可绑定。
				return smartResult(StatusMsg.StatusMsg_120);
			} else {
				//删除这个openid还未认证的
				makerByOpenid.deleteById();
			}
		}

		Company companyByOpenid = companyMapper.getCompanyByOpenid(openid);
		if (companyByOpenid != null) {
			if (NumberUtil.safeInt(companyByOpenid.getState()) > 1) {
				//openid已经注册企业并认证了手机号，不可绑定。
				return smartResult(StatusMsg.StatusMsg_119);
			} else {
				//删除这个openid还未认证的企业
				companyByOpenid.deleteById();
			}
		}

		commonService.checkPhoneVerifyCode(phone, verifycode);

		Maker maker = new Maker().selectOne(Condition.create().eq("phone", phone));
		if (maker == null) return smartResult(StatusMsg.StatusMsg_114);
		if (StringUtil.isNotEmpty(maker.getOpenid())) return smartResult(StatusMsg.StatusMsg_212);

		WxAuthorizeUserInfo userInfo = wxApiService.getAuthorizeUserInfo(accessToken, openid);
		maker.setOpenid(openid)
				.setAvatar(userInfo.getHeadimgurl())
				.setNickname(userInfo.getNickname())
				.setUnionid(userInfo.getUnionid())
				.setSex((StringUtil.toInt(userInfo.getSex())))
				.setState(Constants.user_state_2);
		maker.updateById();
		return smartResult(maker.getUserid());
	}

	public SmartResult getUserAccountStatistics(BaseSimpleFormBean formBean) {
		int userid = formBean.getUserid();
		//查询创客交易金额，不含委托发单/创客团项目金额
		BigDecimal monthBanlance = coreProjectService.getUserMonthlyTotalAmount(userid, CalcAmountType.PROCESSING, 0, 0, false);
		BigDecimal quarterBanlance = coreProjectService.getUserQuarterTotalAmount(userid, CalcAmountType.PROCESSING, false);
		BigDecimal yearlyBanlance = coreProjectService.getUserYearlyTotalAmount(userid,  CalcAmountType.PROCESSING, false);
		//查询这个季度对应的三个月交易额
		int firstMonth = DateUtil.getQuarterNumMonth(new Date(), 1);
		BigDecimal firstMonthIncome = coreProjectService.getUserMonthlyTotalAmount(userid, CalcAmountType.PROCESSING, DateUtil.getNowYear(), firstMonth, false);

		int secondMonth = DateUtil.getQuarterNumMonth(new Date(), 2);
		BigDecimal secondMonthIncome = coreProjectService.getUserMonthlyTotalAmount(userid, CalcAmountType.PROCESSING, DateUtil.getNowYear(), secondMonth, false);

		int thirdMonth = DateUtil.getQuarterNumMonth(new Date(), 3);
		BigDecimal thirdMonthIncome = coreProjectService.getUserMonthlyTotalAmount(userid, CalcAmountType.PROCESSING, DateUtil.getNowYear(), thirdMonth, false);

		Map<Integer, BigDecimal> map = new HashMap<>();
		map.put(firstMonth, firstMonthIncome);
		map.put(secondMonth, secondMonthIncome);
		map.put(thirdMonth, thirdMonthIncome);

		return smartResult(new MakerIncomeDto(monthBanlance, map, quarterBanlance, yearlyBanlance));
	}

	public SmartResult agreeProtocol(BaseSimpleFormBean formBean) {
		int userid = formBean.getUserid();
		int idtype = formBean.getIdtype();
		if (idtype != UserType.MAKER) return errorParamSmartResult();

		boolean update = new MakerAccount().setAgreeProtocol(1).update(Condition.create().eq("userid", userid));
		if (update) return smartResult();
		return optFailSmartResult();
	}

	public SmartResult getFinishTaxList(BaseSimpleFormBean formBean) {
		int userid = formBean.getUserid();
		Page<Object> page = PageHelper.startPage(formBean.getPage(), formBean.getRows());
		makerFinishTaxMapper.getMakerFinishTaxList(userid);
		return smartResultPage(page);
	}

	public SmartResult<MakerAnnualCheckDto> getAnnualCheckList(BaseSimpleFormBean formBean) {
		int userid = formBean.getUserid();
		Page<MakerAnnualCheckDto> page = PageHelper.startPage(formBean.getPage(), formBean.getRows());
		makerAnnualCheckMapper.getMakerAnnualCheckList(userid);
		return smartResultPage(page);
	}

	public SmartResult<MakerFinalSettlementDto> getFinalSettlementList(BaseSimpleFormBean formBean) {
		int userid = formBean.getUserid();
		Page<MakerFinalSettlementDto> page = PageHelper.startPage(formBean.getPage(), formBean.getRows());
		makerFinalSettlementMapper.getMakerFinalSettlementList(userid);
		return smartResultPage(page);
	}

	public SmartResult editMail(BaseSimpleFormBean<EmailFormBean> formBean) {
		EmailFormBean reqdata = formBean.getReqdata();
		String email = reqdata.getEmail();
		int userid = formBean.getUserid();
		MakerAccount account = new MakerAccount().selectOne(Condition.create().eq("userid", userid));
		if (account == null) return smartResult(StatusMsg.StatusMsg_201);

		boolean update = account.setEmail(email).updateById();
		if (update) return smartResult();
		return optFailSmartResult();
	}

//	public SmartResult sendContractEmail(BaseSimpleFormBean<ProjectIdFormBean> formBean) {
//		ProjectIdFormBean reqdata = formBean.getReqdata();
//		int projectid = reqdata.getProjectid();
//
//		CompanyProject project = new CompanyProject().selectById(projectid);
//		if (project == null) {
//			return smartResult(StatusMsg.StatusMsg_301);
//		}
//
//		MakerStudio studio = new MakerStudio().selectById(project.getUserid());
//		if (studio == null) {
//			return smartResult(StatusMsg.StatusMsg_201);
//		}
//
//		File file = docService.getOrCreateContractFile(project, company, studio, null);
//		if (file == null) return optFailSmartResult();
//
//		MakerAccount account = new MakerAccount().selectOne(Condition.create().eq("userid", studio.getUserid()));
//		String subject = "项目合同-" + FilenameUtils.getBaseName(file.getName());
//		String date = DateUtil.getString(project.getProjectstart(), DateUtil.FORMAT_STYLE_3);
//		String content = String.format(mailConfig.getContractMailContent(), date, project.getCompname(), studio.getUsername());
//
//		ArrayList<String> toList = Lists.newArrayList(account.getEmail());
//		ArrayList<String> attachments = Lists.newArrayList(file.getAbsolutePath());
//
//		boolean sent = mailService.sendMailWithAttachments(toList, subject, content, attachments);
//		if (sent) return smartResult();
//		return optFailSmartResult();
//	}

	public SmartResult sendPdfContractEmail(BaseSimpleFormBean<ProjectIdFormBean> formBean) {
		ProjectIdFormBean reqdata = formBean.getReqdata();
		int projectid = reqdata.getProjectid();

		CompanyProject project = new CompanyProject().selectById(projectid);
		if (project == null) {
			return smartResult(StatusMsg.StatusMsg_301);
		}

		MakerStudio studio = new MakerStudio().selectById(project.getUserid());
		if (studio == null) {
			return smartResult(StatusMsg.StatusMsg_201);
		}

		File file = contractDocService.createContractFile(project.getProjectid());
		if (file == null) return optFailSmartResult();

		MakerAccount account = new MakerAccount().selectOne(Condition.create().eq("userid", studio.getUserid()));
		String subject = "项目合同-" + FilenameUtils.getBaseName(file.getName());
		String date = DateUtil.getString(project.getProjectstart(), DateUtil.FORMAT_STYLE_3);
		String content = String.format(mailConfig.getContractMailContent(), date, project.getCompname(), studio.getUsername());

		ArrayList<String> toList = Lists.newArrayList(account.getEmail());
		ArrayList<String> attachments = Lists.newArrayList(file.getAbsolutePath());

		boolean sent = mailService.sendMailWithAttachments(toList, subject, content, attachments);
		if (sent) return smartResult();
		return optFailSmartResult();
	}

	public SmartResult applyRescission(BaseSimpleFormBean<ApplyRescissionFormBean> formBean) {
		@Valid ApplyRescissionFormBean reqdata = formBean.getReqdata();
		String reason = reqdata.getReason();

		int userid = formBean.getUserid();
		int idtype = formBean.getIdtype();
		if (!NumberUtil.intIn(idtype, UserType.MAKER, UserType.MAKER_CROWDSOURCE)) return smartResult(StatusMsg.StatusMsg_214);

		int count = new MakerRescissionApply().selectCount(Condition.create().eq("userid", userid).lt("state", 3));
		if (count > 0) return smartResult(StatusMsg.StatusMsg_219);

		boolean insert = new MakerRescissionApply().setUserid(userid).setReason(reason).setState(1).insert();
		if (insert) return smartResult();
		return optFailSmartResult();
	}

	/**
	 * CEO处理提交注销申请
	 * @param formBean
	 * @return
	 */
	public SmartResult processRescissionApply(BaseSimpleFormBean<ProcessRescissionApplyFormBean> formBean) {
		ProcessRescissionApplyFormBean req = formBean.getReqdata();

		int userid = formBean.getUserid();
		int idtype = formBean.getIdtype();
		if (!NumberUtil.intIn(idtype, UserType.MAKER, UserType.MAKER_CROWDSOURCE)) return smartResult(StatusMsg.StatusMsg_214);

		List<Integer> idList = req.getIdList();
		for (Integer id:idList){
			MakerRescissionApply apply = new MakerRescissionApply().selectById(id);
			Asserts.notNull(apply, StatusMsg.StatusMsg_215);
			apply.setState(req.getState()).setRemark(req.getRemark()).updateById();
		}
		// TODO 发消息给客服
		return smartResult();
	}

	public SmartResult saveBusinessAuthenticationImg(BaseSimpleFormBean<BusinessAuthenticationFormBean> formBean) {
		@Valid BusinessAuthenticationFormBean reqdata = formBean.getReqdata();
		int userid = formBean.getUserid();
		MakerAccount maker = new MakerAccount().selectOne(Condition.create().eq("userid", userid));
		if (maker == null) return SmartResult.fail(StatusMsg.StatusMsg_201);

		Integer realnameAuth = maker.getRealnameAuth();
		if (realnameAuth < Constants.realname_auth_4) {
			return SmartResult.fail(StatusMsg.StatusMsg_202);
		}
		// 每次更新资料,就重新开始计算开工商户的时间
		maker.setOpenStarttime(new Date()).setBusinessAuthenticationImg(reqdata.getImg()).setBusinessAuthenticationState(1).updateById();
		return SmartResult.success();
	}

	/**
	 * 注册工商户
	 *
	 * @param formBean
	 * @return
	 */
	public SmartResult registeredBusiness(BaseSimpleFormBean<RegisteredBusinessFormBean> formBean) {
		if (null == formBean || null == formBean.getReqdata() || 0 == formBean.getReqdata().getUserid()) {
			return smartResult(StatusMsg.StatusMsg_101);
		}
		RegisteredBusinessFormBean reqdata = formBean.getReqdata();
		int userid = reqdata.getUserid();
		MakerAccount maker = new MakerAccount().selectOne(Condition.create().eq("userid", userid));
		if (maker == null) return SmartResult.fail(StatusMsg.StatusMsg_201);
		//先把电子签名图片路径保存下来
		maker.setElectronicSignature(reqdata.getSIGN()).updateById();
		try {
			File f;
			LogUtil.info("要压缩的创客签名参数：" + uploadPathConfig.getOssimgurl() + reqdata.getSIGN() +
					"?x-oss-process=image/resize,h_22,m_lfit/format,jpg");
			String compressPath = FileUtil.downloadFile(
					uploadPathConfig.getOssimgurl() + reqdata.getSIGN() + "?x-oss-process=image/resize,h_22,m_lfit/format,jpg",
					uploadPathConfig.getUploadpath(), 2, "compress");
			LogUtil.info("压缩后的创客签名的路径：" + compressPath);
			if (null == compressPath) {
				f = new File(uploadPath + "/" + reqdata.getSIGN());
			} else {
				f = new File(uploadPath + "/" + compressPath);
			}
			//电子签名转为base64
			String signInfo = FileUtil.fileToBase64(f);
			YunKongRegisteredBusinessFormBean bean = new YunKongRegisteredBusinessFormBean();
			bean.setSIGN(signInfo)
					.setHUITIPLATSRL(reqdata.getHUITIPLATSRL())
					.setSFGHOCRPLATSRL(reqdata.getSFGHOCRPLATSRL())
					.setSFZMOCRPLATSRL(reqdata.getSFZMOCRPLATSRL())
					.setMOBILENO(reqdata.getMOBILENO())
					.setSFRZDBLATSRL(reqdata.getSFRZDBLATSRL());
			RestTemplate restTemplate = new RestTemplate();
			BaseSimpleFormBean<YunKongRegisteredBusinessFormBean> registeredBusinessFormBean = new BaseSimpleFormBean<>();
			registeredBusinessFormBean.setReqdata(bean);
			SmartResult result = restTemplate.postForObject(zddUrlConfig.getYunkongUrl() + yunKongConfig.getBusiness(),
					registeredBusinessFormBean, SmartResult.class);
			if (result != null && result.getState() == StatusMsg.StatusMsg_100.getState()) {
				JSONObject object = result.toJson().getJSONObject("object");
				//获取返回回来的个体户编号
				String firmid = object.getString("FIRMID");
				maker.setIndividualAccountNumber(firmid);
				if (!maker.updateById()) {
					LogUtil.error("注册工商户！保存个体户编号失败！");
					return smartResult(StatusMsg.StatusMsg_199);
				} else {
					//默认审核通过创客个体户
					CompanyExamineFormBean companyExamineFormBean = new CompanyExamineFormBean();
					companyExamineFormBean.setFIRMID(firmid).setSTATUS("1");
					BaseSimpleFormBean<CompanyExamineFormBean> companyExamineBean = new BaseSimpleFormBean<>();
					companyExamineBean.setReqdata(companyExamineFormBean);
					SmartResult result2 = restTemplate.postForObject(zddUrlConfig.getYunkongUrl() + yunKongConfig.getCompanyExamineMaker(),
							companyExamineBean, SmartResult.class);
					if (result2 != null && result2.getState() == StatusMsg.StatusMsg_100.getState()) {
						JSONObject object1 = result2.toJson().getJSONObject("object");
						if (!"true".equals(object1.getString("msg"))) {
							LogUtil.error("创客企业审核审核失败！个体户编号：" + firmid);
							return smartResult(StatusMsg.StatusMsg_199);
						} else {
							maker.setGongQingDataSubmint(1).setGovernmentExamineState("").setGovernmentRejectionReasons("").updateById();
							return smartResult();
						}
					} else {
						LogUtil.error("创客企业审核审核失败！个体户编号：" + firmid);
						return smartResult(StatusMsg.StatusMsg_199);
					}
				}
			} else {
				return result;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return smartResult(StatusMsg.StatusMsg_199);
		}
	}

	/**
	 * 保存创客录制的视频和电子签名
	 *
	 * @param formBean
	 * @return
	 */
	public SmartResult saveMakerVideoAndSignature(BaseSimpleFormBean<SaveVideoAndSignatureFormBean> formBean) {
		if (StringUtil.isAnyEmpty(formBean.getReqdata().getSignaturePath(), formBean.getReqdata().getVideoPath()) || 0 == formBean.getReqdata().getUserid()) {
			return smartResult(StatusMsg.StatusMsg_101);
		}
		MakerAccount makerAccount = new MakerAccount().selectOne(Condition.create().eq("userid", formBean.getReqdata().getUserid()));
		if (makerAccount == null) {
			return SmartResult.fail(StatusMsg.StatusMsg_201);
		}
		makerAccount.setElectronicSignature(formBean.getReqdata().getSignaturePath())
				.setVideoDetection(formBean.getReqdata().getVideoPath())
				.setBusinessDataSubmint(1)
				.setExamineBusinessDataState(0)
				.setRejectBusinessRegisterReason("")
				.setGongQingDataSubmint(0);
		if (!makerAccount.updateById()) {
			LogUtil.info("创客保存电子签名或视频失败！");
			return smartResult(StatusMsg.StatusMsg_199);
		}
		wxMessageService.makerSubmitDataNotify(makerAccount.getAcctid());
		return smartResult();
	}

	public SmartResult updateEmergencyContact(BaseSimpleFormBean<UpdateEmergencyContactFormBean> formBean) {
		UpdateEmergencyContactFormBean temp = formBean.getReqdata();
		Maker update = new Maker();
		BeanUtils.copyProperties(temp, update);
		update.updateById();
		return smartResult();
	}

	public SmartResult getCancelVoucher(@RequestBody BaseSimpleFormBean<MakerCancelVoucher> formBean){
		if(formBean==null || formBean.getReqdata()==null || formBean.getReqdata().getUserid()==null){
			return errorParamSmartResult();
		}
		MakerCancelVoucher reqdata = formBean.getReqdata();
		Maker newMaker = new Maker();
		BeanUtils.copyProperties(reqdata,newMaker);
		Maker maker = newMaker.selectById();
		if(maker==null){
			LogUtil.info("没有对应的创客");
			return smartResult(StatusMsg.StatusMsg_199);
		}
		return smartResult(maker.getCancelVoucher());
	}

	public SmartResult updateElectronicSignature(@RequestBody BaseSimpleFormBean<String> formBean) {
		@Valid String electronicSignature = formBean.getReqdata();
		Asserts.notEmpty(electronicSignature, StatusMsg.StatusMsg_101);
		int userid = formBean.getUserid();
		new MakerAccount().setElectronicSignature(electronicSignature).update(Condition.create().eq("userid", userid));
		return SmartResult.success();
	}

	public SmartResult saveEntrustTaxVideo(BaseSimpleFormBean<String> formBean) {
		String reqdata = formBean.getReqdata();
		Asserts.notEmpty(reqdata, StatusMsg.StatusMsg_101);
		int userid = formBean.getUserid();
		MakerDetailDto userDetail = makerMapper.getUserDetail(userid);
		MakerStudio makerStudio = new MakerStudio().selectById(userid);
		Asserts.notNull(makerStudio, StatusMsg.StatusMsg_228);
		// 支持芜湖地区创客
		Asserts.equals(userDetail.getOpeningLocation(), 3, StatusMsg.StatusMsg_259);
		Asserts.notEquals(makerStudio.getState(), StudioState.CONFIRMED, StatusMsg.StatusMsg_205);

		makerStudio.setEntrustTaxVideoFile(reqdata).setEntrustTaxVideoState(MakerEntrustTaxVideoState.PENDING).updateById();
		return SmartResult.success();
	}

	/**
	 * 创客加急开税户 发送微信
	 * @param formBean
	 * @return
	 */
	public SmartResult manualSendNotify(ManualSendNotifyFormBean formBean){
		//微信消息给赵菲，创客加急开税户，消息内容：***工作室，申请加急办理税户
		Integer userId = formBean.getUserId();
		MakerStudio makerStudio = new MakerStudio().selectById(userId);
		if (makerStudio == null) {
			Asserts.notNull(makerStudio, StatusMsg.StatusMsg_228);
		}
		String info = makerStudio.getUsername() + "工作室，申请加急办理税户";
		new Thread(() -> commonService.sendEnterpriseWeChatNotice(0, "赵菲", 2, info)).start();
		return SmartResult.success();
	}
}
